package com.events;

import java.util.ArrayList;


public class EventTimer {
	private float time;
	private ArrayList<Event> events;
	private ArrayList<Event> removeList;

	/**
	 * This class holds and controls the time of all events
	 */
	public EventTimer() {
		events = new ArrayList<Event>();
		removeList = new ArrayList<Event>();
		time = 0.0f;
	}

	public float getTime() {
		return time;
	}
	
	/**
	 * 
	 * @param e
	 */
	public void removeEvent(Event e) {
		removeList.add(e);
	}

	/**
	 * 
	 * @param e
	 */
	public void addEvent(Event e) {
		events.add(e);
	}

	/**
	 * 
	 * @param dt
	 */
	public void update(float dt) {
//		update time
		time += dt;
		
//		Check active events if they should be finished 
		for (Event e : events) {
			e.checkEndTime(time);
		}
//		Remove events that is in the removelist
		for (Event e : removeList) {
			events.remove(e);
		}
		removeList.clear();
	}
}
